home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / appsrcs.zip / APPUN.ZIP / APPBROWS.C next >
C/C++ Source or Header  |  1993-03-22  |  2KB  |  71 lines

  1. #define STRICT
  2. //compile with the strictest error checking
  3. #define STRICT
  4. #include <windows.h>
  5. #include <windowsx.h>
  6. #include <shellapi.h>
  7. #include <ctl3d.h>
  8. #include "apprun.h"
  9.  
  10.  
  11. // !!!!! Don't forget to link commdlg.dll !!!!!
  12.  
  13. /*--------------------------------------------------------------------------*/
  14. BOOL FAR PASCAL OpenHook(HWND hwnd, int wm, int wParam, long lParam)
  15. {
  16.     switch (wm) {
  17.     case WM_INITDIALOG:
  18.             // We must call this to subclass the directory listbox even
  19.             // if the app calls Ctl3dAutoSubclass (commdlg bug)
  20.             Ctl3dSubclassDlg(hwnd, CTL3D_ALL);
  21.         break;
  22.     }
  23.     return FALSE;
  24. }
  25.  
  26. /*--------------------------------------------------------------------------*/
  27. BOOL PASCAL BrowseFile(HWND hWndCommDlgParent, char *FileName)
  28.     {
  29.     OPENFILENAME ofn;
  30.     char szDirName[256];
  31.     char szFile[256], szFileTitle[256]; /* file and title arrays */
  32.     char *szExeFilter[] = {
  33.     "Executable Files",
  34.     "*.exe;*.com;*.pif",
  35.     "All Files",
  36.     "*.*",
  37.     ""
  38.     };
  39.  
  40.     /* Initialize the OPENFILENAME members */
  41.     GetWindowsDirectory((LPSTR)szDirName, 255);
  42.  
  43.     szFile[0] = '\0';
  44.     ofn.lStructSize = sizeof(OPENFILENAME);
  45.     ofn.hwndOwner = hWndCommDlgParent;
  46.     ofn.lpstrFilter = szExeFilter[0];
  47.     ofn.lpstrTitle = (LPSTR) "AppRun - Browse";
  48.     ofn.lpstrInitialDir = szDirName;
  49.     ofn.lpstrCustomFilter = (LPSTR) NULL;
  50.     ofn.nMaxCustFilter = 0L;
  51.     ofn.nFilterIndex = 1L;
  52.     ofn.lpstrFile= szFile;
  53.     ofn.nMaxFile = sizeof(szFile);
  54.     ofn.lpstrFileTitle = szFileTitle;
  55.     ofn.nMaxFileTitle = sizeof(szFileTitle);
  56.     ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  57.     ofn.lpfnHook = MakeProcInstance(OpenHook, hInst);
  58.     ofn.nFileOffset = 0;
  59.     ofn.nFileExtension = 0;
  60.     ofn.lpstrDefExt = (LPSTR) NULL;
  61.  
  62.     /* Call the GetOpenFilename function */
  63.     if(GetOpenFileName(&ofn))
  64.     {
  65.     strcpy(FileName, (char *) ofn.lpstrFile);
  66.     return TRUE;
  67.     }
  68.     else
  69.     return FALSE;
  70.     }
  71.